﻿using System;

namespace TowerCraneMonitorClient.NetClient.BasicInfo
{
    /// <summary>
    /// 基本信息
    /// </summary>
    public class Entity : NetClient.Entity
    {
        /// <summary>
        /// 塔机在当前塔群中的编号。范围：0-65536
        /// </summary>
        public int TowerId { get; set; }

        /// <summary>
        /// 塔机在所在塔群中的编号。如果没有传递-1.范围：0-65536
        /// </summary>
        public int TowerGroupId { get; set; }

        /// <summary>
        /// 塔机吊绳倍率。2/4/6/8
        /// </summary>
        public Fall Fall { get; set; }

        /// <summary>
        /// 坐标X。塔机的坐标x
        /// </summary>
        public float LocationX { get; set; }

        /// <summary>
        /// 坐标Y。塔机的坐标y
        /// </summary>
        public float LocationY { get; set; }

        /// <summary>
        /// 塔机前臂长度。
        /// </summary>
        public float ForearmLength { get; set; }

        /// <summary>
        /// 塔机后臂长。
        /// </summary>
        public float ReararmLength { get; set; }

        /// <summary>
        /// 塔帽高度。
        /// </summary>
        public float TowerHatHeight { get; set; }

        /// <summary>
        /// 安装经度。塔机所在经度
        /// </summary>
        public float InstallationLongitude { get; set; }

        /// <summary>
        /// 安装纬度。安装纬度
        /// </summary>
        public float InstallationLatitude { get; set; }

        /// <summary>
        /// 指北角度。塔机转角为 0 时与正北夹角，以右为正. 范围：0-360
        /// </summary>
        public float PointNorthAngle
        {
            get => pointNorthAngle;
            set
            {
                if (value < 0 || value > 360)
                    throw new ArgumentOutOfRangeException(
                        nameof(PointNorthAngle),
                        "塔机指北角度超出范围 0 - 360");
                pointNorthAngle = value;
            }
        }
        float pointNorthAngle;

        /// <summary>
        /// 版本号。设备版本号（预留）
        /// </summary>
        public string DeviceVersionNum { get; set; }

        /// <summary>
        /// 基于该对象生成 BasicInfo.Req 报文
        /// </summary>
        /// <param name="errorMessage">失败时返回错误信息，成功时返回 null</param>
        /// <returns>成功时返回 BasicInfo.Req 对象，失败时返回 null</returns>
        public new Req ToReq() => new Req(this);
    }
}
